home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 16027 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.2 KB

  1. Path: nntp.teleport.com!usenet
  2. From: GHouck <hksys@teleport.com>
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Arrays or Pointers?
  5. Date: 9 Apr 1996 07:48:34 GMT
  6. Organization: systems hk
  7. Message-ID: <4kd4oi$k1h@nadine.teleport.com>
  8. References: <4kbsk3$f07@zeus.tcp.co.uk>
  9. NNTP-Posting-Host: ip-pdx07-07.teleport.com
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=us-ascii
  12. Content-Transfer-Encoding: 7bit
  13. X-Mailer: Mozilla 1.22 (Windows; I; 32bit)
  14.  
  15. daveg@tcp.co.uk (David) wrote:
  16. >I'm currently on a C++ course and we seem to be using pointers a fair
  17. >bit. On questioning this, was told that pointers where quicker than
  18. >using arrays. In which situations should I be using arrays over
  19. >pointers and vice versa?
  20. >
  21. David,
  22. I prefer arrays under the following circumstances:
  23.  
  24.   1) when it is easier to understand their use (i.e.: they model the
  25.      real-world entity that is represented by them).
  26.   2) speed is not a high-order issue.
  27.   3) when I need guarantee of contiguous data (i.e.: array[0],[1],...)
  28.  
  29. You can usually use a combination of the two syntaxes when the
  30. pointers refer to contiguous, constant-length, aggregates.
  31. (i.e.: 'letter = string[12];' can usually stand in for: 'letter = *(string+12);')
  32.  
  33. Yours, Geoff Houck
  34.  
  35.